package torres.view;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;

import torres.map.World;

/**
 * @author Torres
 * This class represents the entire panel for the game. There
 * are two panes; area where player walks and the status/inventory
 * view ports.
 */
@SuppressWarnings("serial")
public class MainView extends JFrame {
	
	private AreaViewPort areaViewPort;
	private StatusViewPort statusViewPort;
	private static String name = "LlamAdventure by Team Torres";
	final private int AREA_WIDTH = 800;
	final private int AREA_HEIGHT = 535;
	
	/**
	 * Creates a new MainView with the default settings.
	 */
	public MainView() {
		super(name);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setPreferredSize(new Dimension(AREA_WIDTH, AREA_HEIGHT));
		this.setResizable(false);
	    
		//areaViewPort = new AsciiAreaViewPort();
		areaViewPort = new TwoDAreaViewPort();
		statusViewPort = new StatusViewPort();
		getContentPane().add(areaViewPort, BorderLayout.CENTER);
		getContentPane().add(statusViewPort, BorderLayout.EAST);
		
		this.pack();
		setVisible(true);
	}
	
	/**
	 * Draws the main view -- the area representing the map.
	 */
	public void draw() {
		this.setTitle(name + " - " + World.getInstance().getCurrentMap().mapName());
		areaViewPort.draw();
		statusViewPort.update();
	}
	
	/**
	 * Returns the current AreaViewPort
	 * @return The current AreaViewPort
	 */
	public AreaViewPort getAreaViewPort() {
		return areaViewPort;
	}
	
	/**
	 * Returns the current StatusViewPort
	 * @return The current StatusViewPort
	 */
	public StatusViewPort getStatusViewPort() {
		return statusViewPort;
	}
	
	
	/**
	 * Sets the AreaViewPort to the specified value.
	 * @param area The new AreaViewPort
	 */
	public void setAreaViewPort(AreaViewPort area) {

		if(area.isAscii()){
			this.areaViewPort = new AsciiAreaViewPort();
		}
		else if(area.isTwoD())
			this.areaViewPort = new TwoDAreaViewPort();

		getContentPane().add(areaViewPort, 0);
		getContentPane().validate();
	}
}